package org.arch_learn.rpc.rmi.client;

import org.arch_learn.rpc.rmi.pojo.User;
import org.arch_learn.rpc.rmi.service.IUserService;

import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class RMIClient {
    public static void main(String[] args) throws RemoteException, NotBoundException {
        //1.获取Registry实例
        Registry registry = LocateRegistry.getRegistry("127.0.0.1", 9998);
        //2.通过Registry实例（注册表）查找远程对象
        IUserService userService = (IUserService) registry.lookup("userService");
        User user = userService.findUserById(2);
        System.out.println(user.toString());
    }
}
